package com.blue.gateway.paycore;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author xiaoyiming
 * @date 2020/5/3 15:59
 * @depiction 获取对象
 */
@Slf4j
@Component
public class ChannelServiceFactory implements ApplicationContextAware {
    private static ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ChannelServiceFactory.applicationContext = applicationContext;
    }

    static <T> T getBean(String name, Class<T> clazz) {
        T bean = null;
        try {
            bean = applicationContext.getBean(name, clazz);
        } catch (Exception e) {
            log.error("get bean error, name="+ name + ", clazz=" + clazz, e);
        }
        return bean;
    }

}
